1. Field of the Invention
The present invention relates to performing arithmetic operations on interval operands within a computer system. More specifically, the present invention relates to a method and an apparatus for performing a fast mask-driven division operation between interval operands.
2. Related Art
Rapid advances in computing technology make it possible to perform trillions of computational operations each second. This tremendous computational speed makes it practical to perform computationally intensive tasks as diverse as predicting the weather and optimizing the design of an aircraft engine. Such computational tasks are typically performed using machine-representable floating-point numbers to approximate values of real numbers. (For example, see the Institute of Electrical and Electronics Engineers (IEEE) standard 754 for binary floating-point numbers.)
In spite of their limitations, floating-point numbers are generally used to perform most computational tasks.
One limitation is that machine-representable floating-point numbers have a fixed-size word length, which limits their accuracy. Note that a floating-point number is typically encoded using a 32, 64 or 128-bit binary number, which means that there are only 232, 264 or 2128 possible symbols that can be used to specify a floating-point number. Hence, most real number values can only be approximated with a corresponding floating-point number. This creates estimation errors that can be magnified through even a few computations, thereby adversely affecting the accuracy of a computation.
A related limitation is that floating-point numbers contain no information about their accuracy. Most measured data values include some amount of error that arises from the measurement process itself. This error can often be quantified as an accuracy parameter, which can subsequently be used to determine the accuracy of a computation. However, floating-point numbers are not designed to keep track of accuracy information, whether from input data measurement errors or machine rounding errors. Hence, it is not possible to determine the accuracy of a computation by merely examining the floating-point number that results from the computation.
Interval arithmetic has been developed to solve the above-described problems. Interval arithmetic represents numbers as intervals specified by a first (left) endpoint and a second (right) endpoint. For example, the interval [a, b], where a less than b, is a closed, bounded subset of the real numbers, R, which includes a and b as well as all real numbers between a and b. Arithmetic operations on interval operands (interval arithmetic) are defined so that interval results always contain the entire set of possible values. The result is a mathematical system for rigorously bounding numerical errors from all sources, including measurement data errors, machine rounding errors and their interactions.
Note that the first endpoint normally contains the xe2x80x9cinfimumxe2x80x9d, which is the largest number that is less than or equal to each of a given set of real numbers. Similarly, the second endpoint normally contains the xe2x80x9csupremumxe2x80x9d, which is the smallest number that is greater than or equal to each of the given set of real numbers. Note that the infimum of an interval X can be represented as inf(X), and the supremum can be represented as sup(X).
However, computer systems are presently not designed to efficiently handle intervals and interval computations. Consequently, performing interval operations on a typical computer system can be hundreds of times slower than performing conventional floating-point operations. In addition, without a special representation for intervals, interval arithmetic operations fail to produce results that are as narrow as possible.
What is needed is a method and an apparatus for efficiently performing arithmetic operations on intervals with results that are as narrow as possible. (Interval results that are as narrow as possible are said to be xe2x80x9csharpxe2x80x9d.)
One problem in performing an interval division operation is that the procedure used to perform an interval division operation varies depending upon whether the interval operands are less than zero, greater than zero or contain zero. Hence, code that performs an interval division operation typically performs a number of tests, by executing xe2x80x9cifxe2x80x9d statements, to determine relationships between the interval operands and zero. Executing these xe2x80x9cifxe2x80x9d statements can cause an interval division operation to require a large amount of time to perform.
Another problem in performing an interval division operation is that the system must determine if any of the interval operands are empty, because the result of the interval division operation is the empty interval if any of the interval operands are empty. Testing interval operands for emptiness also involves executing xe2x80x9cifxe2x80x9d statements, which further increases the amount of time required to perform an interval division operation.
What is needed is a method and an apparatus for performing an interval division operation between interval operands that does not involve executing time consuming if statements in order to test the interval operands.
One embodiment of the present invention provides a system for performing a division operation between arithmetic intervals within a computer system. The system operates by receiving interval operands, including a first interval and a second interval, wherein the first interval is to be divided by the second interval to produce a resulting interval. Next, the system uses the values of the interval operands to create a mask. The system next performs a multi-way branch based upon the mask, so that an execution flow of a program performing the division operation is directed to the code that computes the resulting interval for each specific relationship between the interval operands.
In one embodiment of the present invention, creating the mask additionally involves, determining whether the first and/or second intervals is empty, and modifying the mask accordingly. In this embodiment, performing the multi-way branch involves directing the execution flow of the program to the code that computes the resulting interval, depending upon whether the first and/or second interval is empty.
In one embodiment of the present invention, if the first interval is empty or if the second interval is empty, the multi-way branch directs the execution flow of the program to code that sets the resulting interval to be empty.
In one embodiment of the present invention, if the first interval is greater than zero and the second interval is greater than zero, performing the multi-way branch directs the execution flow of the program to code that computes a left endpoint of the resulting interval as a left endpoint of the first interval divided by a right endpoint of the second interval. This code also computes a right endpoint of the resulting interval as a right endpoint of the first interval divided by a left endpoint of the second interval.
In one embodiment of the present invention, if the first interval is greater than zero and the second interval is less than zero, performing the multi-way branch directs the execution flow of the program to code that computes a left endpoint of the resulting interval as a right endpoint of the first interval divided by a right endpoint of the second interval. This code also computes a right endpoint of the resulting interval as a left endpoint of the first interval divided by a left endpoint of the second interval.
In one embodiment of the present invention, if the first interval is less than zero and the second interval is greater than zero, performing the multi-way branch directs the execution flow of the program to code that computes a left endpoint of the resulting interval as a left endpoint of the first interval divided by a left endpoint of the second interval. This code also computes a right endpoint of the resulting interval as a right endpoint of the first interval divided by a right endpoint of the second interval.
In one embodiment of the present invention, if the first interval is less than zero and the second interval is less than zero, performing the multi-way branch directs the execution flow of the program to code that computes a left endpoint of the resulting interval as a right endpoint of the first interval divided by a left endpoint of the second interval. This code also computes a right endpoint of the resulting interval as a left endpoint of the first interval divided by a right endpoint of the second interval.
In one embodiment of the present invention, if the first interval includes zero and the second interval is greater than zero, performing the multi-way branch directs the execution flow of the program to code that computes a left endpoint of the resulting interval as a left endpoint of the first interval divided by a left endpoint of the second interval. This code also computes a right endpoint of the resulting interval as a right endpoint of the first interval divided by a left endpoint of the second interval.
In one embodiment of the present invention, if the first interval includes zero and the second interval is less than zero, performing the multi-way branch directs the execution flow of the program to code that computes a left endpoint of the resulting interval as a right endpoint of the first interval divided by a right endpoint of the second interval. This code also computes a right endpoint of the resulting interval as a left endpoint of the first interval divided by a right endpoint of the second interval.
In one embodiment of the present invention, as a consequence of performing endpoint divisions, if either the left endpoint or the right endpoint of the resulting interval is set to a default NaN value (not-a-number), the system additionally sets the left endpoint of the resulting interval to negative infinity, and sets the right endpoint of the resulting interval to positive infinity.
In one embodiment of the present invention, if the second interval includes zero, performing the multi-way branch directs the execution flow of the program to code that sets the left endpoint of the resulting interval to negative infinity, and sets the right endpoint of the resulting interval to positive infinity.